package com.keya.features.operations;

import com.keya.base.sh.RunShell;
import com.keya.base.sh.RunShellRet;
import com.keya.dicomtask.DicomTask;
import io.micrometer.core.instrument.Metrics;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class PrintFilmOp {
    DicomTask dicomTask;

    private String workspacsPath;

    private String imageName;


    public RunShellRet run() throws Exception {
        return Metrics.timer("op_dcmprint").recordCallable(this::runShellRet);
    }

    public RunShellRet runShellRet() throws Exception {
        String acmd = String.format("dcmprint --config %s/print.json --dcmcfg %s/dcmcfg.cfg", workspacsPath, workspacsPath);
        String[] cmds = {"docker", "run", "--rm",
                "-v", String.format("%s:%s", workspacsPath, workspacsPath),
                imageName,
                "bash", "-c", acmd + " 2>&1"
        };
        return RunShell.runShell(dicomTask.getAeTitle() + " print film", cmds, 60 * 3);
    }
}
